// ActionScript file
package vivek.project.pocketmoney.common.logger
{
	import mx.logging.ILogger;
	import mx.logging.Log;
	import mx.logging.LogEventLevel;

	public class PMLogger
	{
		private static var logger:ILogger=null;
		private static var logs:Array=new Array();
		private static const messageTemplate:String="{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}";
		private static var pmTarget:PMLogTarget=new PMLogTarget();

		public static function flush():int
		{
			var count:int=0;
			var obj:Object=new Object();
			if (logger == null)
			{
				logger=Log.getLogger("vivek.project.pocketmoney");
				Log.addTarget(new PMLogTarget());
				pmTarget.filters["vivek.project.pocketmoney.*"];
			}
			for each (obj in logs)
			{
				logger.log(LogEventLevel.INFO, messageTemplate, obj.module, obj.message, obj.txnId, obj.account, obj.amount, obj.transferAccount, obj.category, obj.expDate);
				count++;
			}
			logs=new Array();
			return count;
		}

		public static function log(module:String, message:String, txnId:Number, account:int, amount:Number, transfer:int, category:int, expDate:Date):void
		{
			if (logger == null)
			{
				logger=Log.getLogger("vivek.project.pocketmoney");
				Log.addTarget(new PMLogTarget());
				pmTarget.filters["vivek.project.pocketmoney.*"];
			}
			logger.log(LogEventLevel.INFO, messageTemplate, module, message, txnId, account, amount, transfer, category, expDate);
		}

		public static function logMisc(module:String, message:String, misc:String):void
		{
			if (logger == null)
			{
				logger=Log.getLogger("vivek.project.pocketmoney");
				Log.addTarget(new PMLogTarget());
				pmTarget.filters["vivek.project.pocketmoney.*"];
			}
			logger.log(LogEventLevel.INFO, messageTemplate, module, message, null, misc);
		}

		public static function logMultiple(module:String, message:String, txnId:Number, account:int, amount:Number, transferAccount:int, category:int, expDate:Date):void
		{
			var obj:Object=new Object();
			obj.module=module
			obj.message=message
			obj.txnId=txnId
			obj.account=account
			obj.amount=amount;
			obj.expDate=expDate;
			obj.transferAccount=transferAccount;
			obj.category=category;
			logs.push(obj);
		}

		public function PMLogger()
		{
			Log.addTarget(new PMLogTarget());
			pmTarget.filters["vivek.project.pocketmoney.*"];
		}
	}
}